<template>
  <div>
    <zbTable ref="tableRef" :api-fun="get_list" @action="action" />
    <!-- 编辑弹窗 -->
    <user-edit
      v-if="showEdit"
      v-model:visible="showEdit"
      :actionStatus="actionStatus"
      :editDataId="editDataId"
      @done="done"
    />
  </div>
</template>

<script setup>
  import { ref, onMounted } from 'vue';
  import zbTable from './components/zbTable/index.vue';
  import { get_list } from '@/api/user/user';
  import {
    PlusOutlined,
    UploadOutlined,
    ClearOutlined,
    RestOutlined
  } from '@ant-design/icons-vue';
  import userEdit from './components/user-edit.vue';
  import { actionFn } from '@/utils/action.js';
  import { daochuFn } from '@/utils/daochu.js';
  // 当前编辑数据
  const current = ref(null);
  // 是否显示编辑弹窗
  const showEdit = ref(false);
  // 编辑数据
  const editDataId = ref(null);
  // 编辑按钮数据
  const actionData = ref({});
  // 获取子组件
  const tableRef = ref(null);
  const actionStatus = ref('add');

  const done = (form) => {
    actionFn(actionData.value, form, reloadTable);
  };
  const reloadTable = () => {
    showEdit.value = false;
    tableRef.value.reload();
  };
  const action = (data) => {
    if (data.action_data.type == 'edit') {
      editDataId.value = data.row_data.id;
      actionData.value = data.action_data;
      showEdit.value = true;
      actionStatus.value = 'edit';
    }
    if (data.action_data.type == 'add') {
      editDataId.value = '';
      showEdit.value = true;
      actionStatus.value = 'add';
      actionData.value = { url: data.row_data.url };
    }
  };
</script>
